<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;
use common\models\Company;

/* @var $this yii\web\View */
/* @var $model common\models\Company */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="company-form">

    <?php $form = ActiveForm::begin(); ?>

    <?= $form->field($model, 'company_name')->textInput(['maxlength' => true]) ?>

    <?= $form->field($model, 'company_no')->textInput(['maxlength' => true]) ?>

    <?= $form->field($model, 'company_type')->dropDownList(Company::itemAlias('company_type')) ?>

    <?= $form->field($model, 'logo')->textInput(['maxlength' => true,'style'=>'width:60%;display: inline; 
    margin:0 20px 10px;']) ?>

    <?= $form->field($model, 'province')->dropDownList(Company::Provincelist()) ?>

    <?= $form->field($model, 'city')->dropDownList(Company::Citylist($model->province)) ?>

    <?= $form->field($model, 'status')->dropDownList(Company::itemAlias('status')) ?>

    <?= $form->field($model, 'address_detail')->textInput(['maxlength' => true]) ?>

    <?= $form->field($model, 'contact_name')->textInput(['maxlength' => true]) ?>

    <?= $form->field($model, 'contact_tel')->textInput(['maxlength' => true]) ?>

    <?= $form->field($model, 'job_title')->textInput(['maxlength' => true]) ?>

    <?= $form->field($model, 'remark')->textInput(['maxlength' => true]) ?>

    <?php // $form->field($model, 'create_time')->textInput() ?>

    <div class="form-group">
        <?= Html::submitButton($model->isNewRecord ? '添加' : '修改', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
    </div>

    <?php ActiveForm::end(); ?>

</div>
<?php $this->beginBlock('footer_js') ?>
//
jQuery(document).ready(function () {
    var button = '<button type="button" data-toggle="modal" data-target="#myModal" id="upload_img_url" upload_field="company-logo"  style="">上传</button>';
    $('#company-logo').after(button);
    $('#upload_img_url').click(function(){
        var upload_field = $(this).attr('upload_field');
        $('#upload_img_iframe').attr('src','/tool/uploadupyun?upload_field='+upload_field);
    });

    //供应商地区的二级联动
    $('#company-province').change(function(){
        var id = $('#company-province').val();
        $('#company-city option').remove();

        //设置默认的url为添加数据、如果是更新数据，则将url修改
        var upid = <?php echo intval(Yii::$app->request->get('id'))?>;
        var url = 'city';  
        if(upid){
            url = '../city';
        }
        $.post(url, { id: id }, function(data){ 
            data = eval('('+data+')');
            for(var k in data){
                $('#company-city').append(
                    '<option value="' + k + '">'+data[k]+'</option>'
                )
            }
        });
    });

});
<?php $this->endBlock() ?>  
<?php $this->registerJs($this->blocks['footer_js'], \yii\web\View::POS_END); ?>  
